﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class web_pages_nhatuyedung_tao_vieclamtrong : System.Web.UI.Page
{
	Common comm=new Common();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["NTDuser"] == null)
        {
            Response.Redirect("nhatuyendung.aspx");
        }
        chk_luong_thoa_thuan.Attributes.Add("onClick", "$('#muc_luong_div').toggle();");
        if (!IsPostBack){
		    LoadThoiGianLamViec();
            LoadTP();
            LoadKNMem();
            LoadLoaiVLT();
            LoadNguonVLT();
			txt_ngay_nhan_ho_so.SelectedDate = DateTime.Now.Date;
            txt_ngay_cham_duc.SelectedDate = DateTime.Parse(comm.execScalar("SELECT DATEADD(month,1,GETDATE())"));
        }
	
    }
    protected void LoadThoiGianLamViec()
    {
        Common comm = new Common();

        string sqlComm = "Select ma_thoi_gian_lv, ten_thoi_gian_lv from DanhMuc_thoi_gian_lam_viec   ";
        DataTable dtt = comm.getDataTable(sqlComm);
        for (int i = 0; i < dtt.Rows.Count; i++)
        {
            cbb_thoi_gian_lam_viec.Items.Add(new ListItem(dtt.Rows[i]["ten_thoi_gian_lv"].ToString(), dtt.Rows[i]["ma_thoi_gian_lv"].ToString()));
        }
    }
    protected void LoadTP()
    {
        Common comm = new Common();

        string sqlComm = "Select ma_dia_chi, ten_dia_chi from DanhMuc_dia_chi where muc=0 order by uu_tien,ten_dia_chi ";
        DataTable dtt = comm.getDataTable(sqlComm);
        for (int i = 0; i < dtt.Rows.Count; i++)
        {
            cbb_list_ho_khau.Items.Add(new ListItem(dtt.Rows[i]["ten_dia_chi"].ToString(), dtt.Rows[i]["ma_dia_chi"].ToString()));
            cbb_list_noilamviec.Items.Add(new ListItem(dtt.Rows[i]["ten_dia_chi"].ToString(), dtt.Rows[i]["ma_dia_chi"].ToString()));
            cbb_tinhthanh.Items.Add(new ListItem(dtt.Rows[i]["ten_dia_chi"].ToString(), dtt.Rows[i]["ma_dia_chi"].ToString()));
        }
    }
    protected void LoadKNMem()
    {
        Common comm = new Common();

        string sqlComm = "Select ma_kn_mem, ten_kn_mem from DanhMuc_kha_nang_mem where kich_hoat = 1  ";
        DataTable dtt = comm.getDataTable(sqlComm);
        for (int i = 0; i < dtt.Rows.Count; i++)
        {
            cbb_list_ky_nang_mem.Items.Add(new ListItem(dtt.Rows[i]["ten_kn_mem"].ToString(), dtt.Rows[i]["ma_kn_mem"].ToString()));
        }
    }
  
    
    protected void LoadLoaiVLT()
    {
        Common comm = new Common();

        string sqlComm = "Select ma_loai_vlt, ten_loai_vlt from DanhMuc_loai_viec_lam_trong  ";
        DataTable dtt = comm.getDataTable(sqlComm);
        for (int i = 0; i < dtt.Rows.Count; i++)
        {
            cbb_loai_vlt.Items.Add(new ListItem(dtt.Rows[i]["ten_loai_vlt"].ToString(), dtt.Rows[i]["ma_loai_vlt"].ToString()));
        }
    }
    protected void LoadNguonVLT()
    {
        Common comm = new Common();

        string sqlComm = "Select ma_nguon_vlt, ten_nguon_vlt from DanhMuc_nguon_viec_lam_trong  ";
        DataTable dtt = comm.getDataTable(sqlComm);
        for (int i = 0; i < dtt.Rows.Count; i++)
        {
            cbb_nguon_vlt.Items.Add(new ListItem(dtt.Rows[i]["ten_nguon_vlt"].ToString(), dtt.Rows[i]["ma_nguon_vlt"].ToString()));
        }
    }

    protected void btn_ok_Click(object sender, EventArgs e)
    {
        Common comm = new Common();
        objViecLamTrong objVLT = new objViecLamTrong();
        objVLT.ho_khau = txt_list_hokhau_hidden.Value;
        objVLT.kich_hoat = false;//chk_kich_hoat.Checked;
        objVLT.kieu_tien = cbb_kieu_tien.SelectedValue;
        objVLT.luong_den = (chk_luong_thoa_thuan.Checked) ? 0 : (float) txt_luong_den.Value;
        objVLT.luong_tu = (chk_luong_thoa_thuan.Checked) ? 0 : (float) txt_luong_tu.Value;
        objVLT.ma_chuc_danh = txt_chuc_danh_hidden.Value;
        objVLT.ma_doanh_nghiep = Session["NTDid"].ToString();
        objVLT.ma_loai_vlt = cbb_loai_vlt.SelectedValue;
        objVLT.ma_nguon_vlt = cbb_nguon_vlt.SelectedValue;
       
        objVLT.ma_thoi_gian = cbb_thoi_gian_lam_viec.SelectedValue;
        objVLT.mo_ta = comm.TextFormat(txt_mo_ta_cong_viec.Text);
        objVLT.ngay_dang = DateTime.Now;
		if(txt_ngay_du_tuyen.SelectedDate==null)
			objVLT.ngay_du_tuyen =txt_ngay_cham_duc.SelectedDate.Value;
		else
			objVLT.ngay_du_tuyen = txt_ngay_du_tuyen.SelectedDate.Value;
        objVLT.ngay_het_han = txt_ngay_cham_duc.SelectedDate.Value;
        objVLT.ngay_nhan = txt_ngay_nhan_ho_so.SelectedDate.Value;
        objVLT.noi_du_tuyen = comm.TextFormat(txt_noi_du_tuyen.Text);
        objVLT.noi_lam_viec = txt_list_noilamviec_hidden.Value;
        objVLT.noi_nop_ho_so = comm.TextFormat(txt_noi_nhan_ho_so.Text);
        objVLT.quyen_loi = comm.TextFormat(txt_quyen_loi.Text);
        objVLT.so_luong_tuyen = Convert.ToInt32(txt_so_luong_tuyen.Value);
        objVLT.yeu_cau_giay_to = comm.TextFormat(txt_giay_to.Text);
        objVLT.tieu_de_ho_so = comm.TextFormat(txt_tieu_de.Text);
        objVLT.vi_tri_tuyen_dung = comm.TextFormat(txt_vi_tri_tuyen_dung.Text);
        objVLT.yeu_cau_khac = comm.TextFormat(txt_yeu_cau_khac.Text+"|"+Request.ServerVariables["REMOTE_ADDR"].ToString());
        
        
        char[] sl1 = new char[]{'@'};
        char[] sl2 = new char[]{'#'};
        string tmp="";
        string[] tmps1;
        string[] tmps2;
        #region MyRegion
        // Yeu cau chuyen mon
        objYeuCauChuyenMon objYCM;
        if (txt_cbb_list_chuyen_mon_hidden.Value.Length > 3)
        {
            tmp = txt_cbb_list_chuyen_mon_hidden.Value;
            tmps1 = tmp.Split(sl1);
            for (int i = 0; i < tmps1.Length-1; i++)
            {
                objYCM = new objYeuCauChuyenMon();
                tmps2 = tmps1[i].Split(sl2);
                objYCM.ma_chuyen_mon = tmps2[0];
                objYCM.kinh_nghiem = Convert.ToInt32(tmps2[1]);
                objYCM.ma_hoc_van = tmps2[2];
                objYCM.ma_hang_tn = tmps2[3];
                objVLT.listYeuCauChuyenMon.Add(objYCM);
            }
        } 
        #endregion
        #region Yêu cầu về người
        // Yeu cau người
        // @gioitinh#so luong#nang_tu#nang den# cao tu# cao_den#tuoi tu# tuoiden#mota

        objYeuCauVeNguoi objYCN;
        if (txt_list_con_nguoi_hidden.Value.Length > 3)
        {
            tmp = txt_list_con_nguoi_hidden.Value;
            tmps1 = tmp.Split(sl1);
            for (int i = 0; i < tmps1.Length - 1; i++)
            {
                objYCN = new objYeuCauVeNguoi();
                tmps2 = tmps1[i].Split(sl2);
                objYCN.gioi_tinh = tmps2[0].ToString();//-1 | 1 | 0
                objYCN.so_luong = tmps2[1];
                objYCN.nang_tu = Convert.ToInt32(tmps2[2]);
                objYCN.nang_den = Convert.ToInt32(tmps2[3]);
                objYCN.cao_tu = Convert.ToInt32(tmps2[4]);
                objYCN.cao_den = Convert.ToInt32(tmps2[5]);
                objYCN.tuoi_tu = Convert.ToInt32(tmps2[6]);
                objYCN.tuoi_den = Convert.ToInt32(tmps2[7]);
                objVLT.listYeuCauVeNguoi.Add(objYCN);
            }
        }
        #endregion
        #region MyRegion
        // Yeu kha nang mem
        // 

        objYeuCauKhaNangMem objYCKNM;
        if (cbb_list_ky_nang_mem_hidden.Value.Length > 3)
        {
            tmp = cbb_list_ky_nang_mem_hidden.Value;
            tmps1 = tmp.Split(sl1);
            for (int i = 0; i < tmps1.Length-1; i++)
            {
                objYCKNM = new objYeuCauKhaNangMem();

                objYCKNM.ma_kn_mem = tmps1[i];

                objVLT.listYeuCauKhaNangMem.Add(objYCKNM);
            }
        } 
        #endregion
        #region MyRegion
        // Yeu nghiep vu

        objYeuCauNghiepVu objYCNV;
        if (txt_list_nghiepvu_hidden.Value.Length > 3)
        {
            tmp = txt_list_nghiepvu_hidden.Value;
            tmps1 = tmp.Split(sl1);
            for (int i = 0; i < tmps1.Length-1; i++)
            {
                objYCNV = new objYeuCauNghiepVu();
                tmps2 = tmps1[i].Split(sl2);
                objYCNV.ma_nghiep_vu = tmps2[0];
                objYCNV.ma_hang = tmps2[1];
                objVLT.listYeuCauNghiepVu.Add(objYCNV);
            }
        } 
        #endregion

        ViecLamTrong vltCommon = new ViecLamTrong();
        vltCommon.InsertVLT(objVLT);

        Response.Redirect("notice.aspx?backurl=NTV_Home");

    }
}
